import {
	createRouter,
	createWebHashHistory
} from "vue-router"
//引入组件
// import Home from "./components/Home"
import Blog from "./components/Blog"
import List from "./components/List"
import Login from "./components/Login"

//设置路由
const router = createRouter({
	history: createWebHashHistory(),
	routes: [
		// {
		//     path:"/",
		//     component:Home
		// },
		{
			path: '/',
			component: List
		},
		{
			path: "/blog/:id",
			component: Blog
		},
		{
			path: "/login",
			component: Login
		}
	]

});

//路由守卫 导航守卫
router.beforeEach((to,from,next) => {
	//验证token，只有存在token的时候，才能跳转到内容页
	let token = localStorage.getItem("token");
	if (token=== "123456" || to.path === "/login"){
		next();
	}else{
		next("/login");
	}
})

//暴露路由
export default router;
